<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  notice: czq
  Date: 2018/5/16
  Time: 11:57
  To change this template use File | Settings | File Templates.
--%>
<%@page pageEncoding="UTF-8" language="java" %>
<%@ include file="/commons/global.jsp"%>
<html>
<head>
    <title>添加公告</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/respond.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/h-ui.admin/css/style.css" />
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
</head>
<body>
    <article class="cl pd-20">
        <form  method="post" action="<%=request.getContextPath()%>/manage/notice/noticeUpdate" id="noticeForm" class="form form-horizontal" >
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" hidden name="id" value="${notice.id}">
                    <input type="text" hidden name="user.id" value="${notice.user.id}">
                    <input type="text" class="input-text" value="${notice.title}" placeholder="" id="title" name="title">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>发布者：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="${notice.user.name}" placeholder="" readonly>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>内容：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea name="content" cols="" rows="" class="textarea"  dragonfly="true">${notice.content}</textarea>
                    <p class="textarea-numberbar"></p>
                </div>
            </div>
            <div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-6">
					<button id="noticeAdd" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
					<button id="cancel" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
        </form>
    </article>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery/1.9.1/jquery.min.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/layer/2.4/layer.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui/js/H-ui.js"></script> 
	<script type="text/javascript" src="<%=request.getContextPath()%>/static/h-ui.admin/js/H-ui.admin.page.js"></script> 
	<script type="text/javascript">
		$("#cancel").click(function(){
			parent.layer.close(parent.index);
		});
		
		function noticeAdd() {
			var data = $("#noticeForm").serialize();
			$.ajax({
				url: $("#noticeForm").attr("action"),
				data: data,
				type: "post",
				dataType: "json",
				success: function(result){
					if(result.success){
						top.layer.open({
							icon: 1,
							content: '保存成功！',
							time: 1500
						});
						$(window.parent.document).find("#pageForm").submit();
						parent.layer.close(parent.index);
					}else{
						top.layer.open({
							icon: 2,
							content: result.msg,
							time: 1500
						});
					}
				},
                fail:function(){
                    top.layer.open({
                        icon: 2,
                        content: "系统错误！",
                        time: 1500
                    });
                }
			});
		}

        $(function(){

            /* 校验 */
            var noticeForm;

            $("#noticeAdd").click(function(){
                if(!noticeForm.form()){
                    return false;
                }else{
                    noticeAdd();
                }
            });

            noticeForm = $("#noticeForm").validate({
                "rules":{
                    "title":{
                        "required":true
                    },
                    "content":{
                        "required":true
                    }
                },
                "messages":{
                    "title":{
                        "required":"标题不能为空！"
                    },
                    "content":{
                        "required":"内容不能为空！"
                    }
                }
            });
        });
	</script>
</body>
</html>
